﻿using System;

namespace ButsaScraperLib.Caches
{
	public class CacheFactory
	{
		private static volatile CacheFactory _instance;

		private static readonly object SyncRoot = new object();

		public static CacheFactory Instance
		{
			get
			{
				if (_instance == null)
				{
					lock (SyncRoot)
					{
						if (_instance == null)
						{
							_instance = new CacheFactory();
						}
					}
				}
				return _instance;
			}
		}

		private CacheFactory()
		{
			_teamIdByCodeCache = new GenericCache("TeamIdByCodeCache.data");
			_teamIdByNameCache = new GenericCache("TeamIdByNameCache.data");
			_divisionIdByNameCache = new GenericCache("DivisionIdByNameCache.data");
		}
		
		private readonly GenericCache _teamIdByCodeCache;

		private readonly GenericCache _teamIdByNameCache;

		private readonly GenericCache _divisionIdByNameCache;

		public GenericCache GetCache(CacheType cacheType)
		{
			switch (cacheType)
			{
				case CacheType.TeamIdByCode:
					return _teamIdByCodeCache;
				case CacheType.TeamIdByName:
					return _teamIdByNameCache;
				case CacheType.DivisionIdByName:
					return _divisionIdByNameCache;
				default:
					throw new ArgumentOutOfRangeException("cacheType");
			}
		}

	}
}
